using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace DareMusicFixer
{
    public class Log
    {
        #region Private Member Variables
        private TextBox logBox;
        private static Log instance;
        #endregion

        #region Constructor
        public Log(TextBox box)
        {
            logBox = box;
            instance = this;
        }
        #endregion

        #region Public Static Methods
        public static void Write(string s)
        {
            instance.LogWrite(s);
        }

        public static void WriteLine(string s)
        {
            Write(s + System.Environment.NewLine);
        }

        public static void WriteBreak()
        {
            WriteLine("----------------------------------------");
        }

        public static void Clear()
        {
            instance.LogClear();
        }
        #endregion

        #region Private Methods
        delegate void LogClearDelegate();
        private void LogClear()
        {
            if (logBox.InvokeRequired)
            {
                LogClearDelegate d = new LogClearDelegate(LogClear);
                logBox.Invoke(d);
            }
            else
            {
                logBox.Clear();
            }
        }

        delegate void LogDelegate(string s);
        private void LogWrite(string s)
        {
            if (logBox.InvokeRequired)
            {
                LogDelegate ld = new LogDelegate(LogWrite);
                logBox.Invoke(ld, new object[] { s });
            }
            else
            {
                logBox.AppendText(s);
            }
        }
        #endregion
    }
}
